package com.qfjy.config.mq.example3;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName WeatherConfig
 * @Description TODO
 * @Author guoweixin
 * @Date 2023/4/13
 * @Version 1.0
 */
@Configuration
public class WeatherConfig {
    /**
     * 1、定义交换机 （FanoutExchange)
     * 2、定义2个队列 京东   淘宝
     * 3、交换机和队列进行绑定
     */
    @Bean
    public FanoutExchange weatherFanoutExchange(){

        return new FanoutExchange("weatherFanoutExchange");
    }

    /**
     * 定义队列   京东 淘宝
     */
    @Bean
    public Queue tbFanoutQueue(){
        return new Queue("tbFanoutQueue");
    }

    @Bean
    public Queue jdFanoutQueue(){
        return new Queue("jdFanoutQueue");
    }

    /**
     * 交换机和队列进行绑定
     */
    @Bean
    public Binding bindFanoutTb(Queue tbFanoutQueue,FanoutExchange weatherFanoutExchange){
        return BindingBuilder.bind(tbFanoutQueue).to(weatherFanoutExchange);
    }

    @Bean
    public Binding bindFanoutJd(){
        return BindingBuilder.bind(jdFanoutQueue()).to(weatherFanoutExchange());
    }
}
